
#REPLICATION OF "Should I immunize myself against Internet hoaxes on vaccination? An experimental assessment of source and message credibility"

use "S2_data.dat"

** MODEL 1 

reg  credible  i.condition x2rev  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8  , r

margins condition
 est store uno
 
*outreg2 [ uno  ] using newtable2.xls ,replace
# Graph treatment effects with CI

collapse (mean) y_mean= credible (sd) y_sd= credible (count) n=credible, by( condition)
generate hiwrite = y_mean + invttail(n-1,0.05)*(y_sd / sqrt(n))
generate lowrite = y_mean - invttail(n-1,0.05)*(y_sd / sqrt(n))
graph twoway (bar y_mean condition) (rcap hiwrite lowrite condition )

graph twoway (bar y_mean condition) (rcap hiwrite lowrite condition ) , ysc(r(0 100))


clear
*use "/Users/laurasudulich/Dropbox/MPSA2016/STATA/Jan2017/January2017.dta"

** MODEL 2

# Interaction x2 vaccinations
reg  credible  i.condition##c.x2rev  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8   , r
est store two
outreg2 [ uno two ] using Table2_Aug18.xls ,  alpha (0.001, 0.01, 0.05)  replace

outreg2 [ uno two ] using Table2_Aug27.xls ,  alpha (0.001, 0.01, 0.05) ci replace



margins condition, dydx(x2rev)
 margins, at(condition=(0 1 2 3 ) x2rev=(0(10)-100)) vsquish 
 margins, dydx(condition) at(x2rev=(0(10)-100)) vsquish 
 # Line 8 displays differences that can be visulized here
 marginsplot, yline(0)
 twoway (scatter credible x2rev, msym(oh) jitter(3))(lfitci credible x2rev if condition==0)(lfitci credible x2rev if condition==1) (lfitci credible x2rev if condition==2)(lfitci credible x2rev if condition==3)

 
 *** MODEL 3
 
 ivprobit E1  x2rev  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8    (credible=i.condition) , first 

 *** FIRST STAGE US EQUAL TO MODEL 1
 
 
outreg2  using table3_Aug18.doc, alpha(0.001, 0.01, 0.05)   replace
 
outreg2  using table3_Aug27.doc, alpha(0.001, 0.01, 0.05) ci  replace
 
 margins, at(credible= 0 ) predict(pr)
 margins, at(credible= 50 ) predict(pr)
 margins, at(credible= 100 ) predict(pr)
 margins, at(credible= (0(10)100 )) predict(pr)
 marginsplot

 
 *** Replicating the 2 simultaneous equation 'manually'
 
 * Firts equation
 reg  credible  i.condition x2rev  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8   , r
 est store stage1
 *  predicting fitted values
 predict yhat
 logit E1  x2rev  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8 yhat
 est store stage2
 outreg2 [ stage1 stage2  ] using appendix.xls ,  replace

  margins, at(yhat= 0 ) predict(pr)
   margins, at(yhat= 50 ) predict(pr)
    margins, at(yhat= 100 ) predict(pr)
	 margins, at(yhat= (0(10)100 )) predict(pr)
	 marginsplot
   

   
   
   *** November 26 ***
 reg  credible  i.condition##c.x2rev  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8   , r
  
  ### what we show now
   margins, at( x2rev=(0(10)-100)condition=(0 1 2 3 )) vsquish
   ** or quietly margins condition, at( x2rev=(0(10)-100)) vsquish
   marginsplot, 
   #addplot(hist x2rev)
   *ylabel(0(10)-100) below)
   
*** what we want is probably
   
margins, dydx(condition) at(x2rev=(0(10)-100)) vsquish 
#output in excel

marginsplot, yline(0)
   
 reg  credible  i.condition##c.x2rev  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8   , r
testparm i.condition#c.x2rev

 # breakdown of observations
 tab condition if x2rev<-90 & x2rev>-100 & e(sample)
 tab condition if x2rev<-80 & x2rev>-90 & e(sample)
 tab condition if x2rev<-70 & x2rev>-80 & e(sample)
 tab condition if x2rev<-60 & x2rev>-70 & e(sample)
 tab condition if x2rev<-50 & x2rev>-60 & e(sample)
 tab condition if x2rev<-40 & x2rev>-50 & e(sample)
 tab condition if x2rev<-30 & x2rev>-40 & e(sample)
 tab condition if x2rev<-10 & x2rev>-20 & e(sample)
 tab condition if x2rev<0 & x2rev>-10 & e(sample)
 
 
 
 *** we could bring back the original variable for attitudes
  reg  credible  i.condition##c.x2  i.med_s  kids A2 i.A5 age l_r    religion extrem_lr  x1  x3 x4 x5 x6 x7 x8   , r
   quietly margins condition, at( x2=(0(10)100)) vsquish
   marginsplot
   margins, dydx(condition) at(x2=(0(10)100)) vsquish 
marginsplot, addplot (histogram x2, percent) ysc(r(0 100))
